<template>
	<view class="content">
		<!-- <uni-nav-bar
		statusBar="true" 
		:fixed="true" 
		 leftIcon="back" 
		 @click-left="back"
		backgroundColor="#eff3f7"
		:border="false">
			
		</uni-nav-bar> -->
		<view class="tab-nav">
			<view :class="tabIndex==0?'active':''" @tap.stop="selectTab('0')">{{i18n.RechargeRecord}}</view>
			<view :class="tabIndex==1?'active':''" @tap.stop="selectTab('1')">{{i18n.WithdrawalRecords}}</view>
		</view>
		<view class="contanct">
			<template v-if="list.length>0">
				<block v-for="(item,index) in list" :key="index">
					<view class="list" @tap.stop="jumpDetail(index)">
						<view class="item">
							<view class="">
								{{title_en}}{{tabIndex==0?i18n.recharge:i18n.withdrawal}}
							</view>
							<text>{{item.create_time}}</text>
						</view>
						<view class="item" :class="item.status==3?'orag':item.status==1?'green':'gray'">
							<view class="">
								{{tabIndex==0?'+':'-'}}{{item.number}}
							</view>
							<text>{{item.status==3?((tabIndex==0?i18n.recharge:i18n.withdrawal) + i18n.success):item.status==1?i18n.underReview:i18n.turnDown}}</text>
						</view>
					</view>
				</block>
			</template>
			<template v-else>
				<view class="nodata">{{i18n.nodata}}</view>
			</template>
		</view>
		<load v-if="showLoad"></load>
	</view>
</template>

<script>
	import Load from '../../components/common/load.vue';
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
	import {fetch, showToast, pageto} from '@/common/js/util.js'
	import {mapGetters} from 'vuex' 
	export default {
		computed:  {
			i18n() {
				return this.$t('message');
			},
			...mapGetters([
				'getRequestUrl',
				"getLoginInfo",
				'getLangType',
				'getLang'
			])
		},
		components:{
			uniNavBar,Load
		},
		data() {
			return {
				showLoad:false,
				tabIndex:0,
				tokenId:'',
				title_en:'',
				list:[],
				page:1
			}
		},
		onReachBottom(){
			//触底加载更多
			this.getAddressLists() 
		},
		onPullDownRefresh(){
			//上拉刷新
			this.page = 1;
			this.list = [];
			this.getList()
			setTimeout(()=>{
				uni.stopPullDownRefresh()
			},1000)
		},
		onLoad(e){
			this.title_en = JSON.parse(e.item).title_en;
			this.tokenId = JSON.parse(e.item).token_id;
			this.getList();
		},
		methods:{
			back(){
				uni.navigateBack({
					delta:1
				})
			},
			jumpDetail(index){
				this.list.forEach((item,index)=>{
					this.list[index].type = this.tabIndex==0?0:1;
					this.list[index].title_en = this.title_en;
				})
				uni.navigateTo({
					url:`/pages/wallet/detail?item=${JSON.stringify(this.list[index])}`
				})
			},
			selectTab(index){
				this.tabIndex = index;
				this.page = 1;
				this.list = [];
				this.getList();
			},
			getAddressLists(){
				let url = this.getRequestUrl + '/api/wallet/history';
				let data = {
					id       : this.getLoginInfo.id,
					token    : this.getLoginInfo.token,
					page     : this.page,
					rows     : 10,
					type     : this.tabIndex=='0'?1:2,
					token_id : this.tokenId
				}
				// uni.showLoading()
				this.showLoad = true;
				fetch(url,data,"POST").then(res=>{
					// uni.hideLoading()
					this.showLoad = false;
					if(res.data.code == 1){
						if(res.data.data.data.length==0){
							return
						}
						this.page++;
						this.list = this.list.concat(res.data.data.data);
					}else if(res.data.code ==2){
						showToast(res.data.msg)
						uni.navigateTo({
							url:"/pages/new-login/new-login"
						})
					}
				}).catch(err=>{
					// uni.hideLoading()
					this.showLoad = false;
				})
			},
			getList(){
				let url = this.getRequestUrl + '/api/wallet/history';
				let data = {
					id       : this.getLoginInfo.id,
					token    : this.getLoginInfo.token,
					page     : this.page,
					rows     : 10,
					type     : this.tabIndex=='0'?1:2,
					token_id : this.tokenId
				}
				// uni.showLoading()
				this.showLoad = true;
				fetch(url,data,"POST").then(res=>{
					// uni.hideLoading()
					this.showLoad = false;
					if(res.data.code == 1){
						if(res.data.data.data.length==0){
							return
						}
						this.page++;
						this.list = res.data.data.data;
					}else if(res.data.code ==2){
						showToast(res.data.msg)
						uni.navigateTo({
							url:"/pages/new-login/new-login"
						})
					}
				}).catch(err=>{
					this.showLoad = false;
					// uni.hideLoading()
				})
			},
			getLists(){
				let url = this.getRequestUrl + '/api/wallet/history';
				let data = {
					id       : this.getLoginInfo.id,
					token    : this.getLoginInfo.token,
					page     : this.page,
					rows     : 10,
					type     : this.tabIndex=='0'?1:2,
					token_id : this.tokenId
				}
				// uni.showLoading()
				this.showLoad = true;
				fetch(url,data,"POST").then(res=>{
					// uni.hideLoading()
					this.showLoad = false;
					if(res.data.code == 1){
						if(res.data.data.data.length==0){
							return
						}
						this.page++;
						this.list = this.list.concat(res.data.data.data);
					}
					
				}).catch(err=>{
					// uni.hideLoading()
					this.showLoad = false;
				})
			}
		}
	}
</script>
<style>
	page{
		background: #eff3f7;
	}
</style>
<style lang="scss" scoped>
	.content{
		.tab-nav{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 100upx;
			position: relative;
			&::after{
				position: absolute;
				content: '';
				width: 2upx;
				height: 30upx;
				left: 50%;
				top: 30%;
				transform: translate(-50%);
				background-color: #000;
			}
			view{
				flex: 1;
				text-align: center;
				font-weight: bold;
				line-height: 70rpx;
				&.active{
					color: #24395e;
					position: relative;
					&::after{
						position: absolute;
						content: '';
						width: 72upx;
						height: 5upx;
						left: 50%;
						bottom: 0;
						transform: translateX(-50%);
						background-color: #24395e;
					}
				}
			}
		}
		.contanct{
			padding: 30upx;
			.nodata{
				text-align: center;
				font-size: 26upx;
				color: #999999;
				line-height: 60upx;
			}
			.list{
				display: flex;
				justify-content: space-between;
				background-color: #FFFFFF;
				border-radius: 10upx;
				margin-bottom: 20upx;
				padding:28upx 15upx;
				.item{
					&:first-child{
						view{
							color: #232323;
							font-size:25upx;
							font-weight: bold;
						}
						text{
							color: #8B8B8B;
							font-size:20upx;
						}
					}
					&:last-child{
						text-align: right;
						&.orag{
							color: #FF691A;
							view{
								font-size:25upx;
								font-weight: bold;
							}
							text{
								font-size:20upx;
							}
						}
						&.green{
							color: #1aa034;
							view{
								font-size:25upx;
							}
							text{
								font-size:20upx;
							}
						}
						&.gray{
							color: #9fa2a8;
							view{
								font-size:25upx;
							}
							text{
								font-size:20upx;
							}
						}
					}
				}
			}
		}
	}
</style>
